// 版权归陈超所有

#pragma once

#include "CoreMinimal.h"
#include "UI/WidgetController/CC_WidgetController.h"
#include "CC_OverlayWidgetController.generated.h"

struct FGameplayTagContainer;
class UCC_AbilitySystemComponent;
struct FOnAttributeChangeData;
class UCC_AttributeSet;

/*数据表行结构:用于存储标签信息*/
#pragma region FUIWidgetRow
USTRUCT(BlueprintType)
struct FUIWidgetRow : public FTableRowBase
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	FGameplayTag MessageTag = FGameplayTag();		//标签

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	FText Message = FText();						//描述
	
	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	TSubclassOf<UCC_UserWidget> MessageWidget;		//小部件

	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	UTexture2D* Image = nullptr;					//图片
};
#pragma endregion

/*动态多播委托*/
#pragma region Signature
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAttributeChangedSignature, float, NewValue);

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMessageWidgetRowSignature, FUIWidgetRow, Row);
#pragma endregion

/**
 * 
 */
UCLASS(Blueprintable)
class CC_AURA_API UCC_OverlayWidgetController : public UCC_WidgetController
{
	GENERATED_BODY()
public:
	/*广播初始值*/
	virtual void BroadcastInitialValues() override;
	
	/*依赖的绑定回调函数
	 * 1.监听属性变化
	 * 2.监听效果演员标签
	 */
	virtual void BindCallbacksToDependencies() override;
	
/***************************************************************************************/
/*                                      Attribute相关                                   */
/***************************************************************************************/

#pragma region Attribute
		
protected:
	/*动态多播委托*/
	UPROPERTY(BlueprintAssignable, Category="GAS|Attributes")
	FOnAttributeChangedSignature OnHealthChanged;
	
	UPROPERTY(BlueprintAssignable, Category="GAS|Attributes")
	FOnAttributeChangedSignature OnMaxHealthChanged;
	
	UPROPERTY(BlueprintAssignable, Category="GAS|Attributes")
	FOnAttributeChangedSignature  OnManaChanged;
	
	UPROPERTY(BlueprintAssignable, Category="GAS|Attributes")
	FOnAttributeChangedSignature OnMaxManaChanged;

private:


#pragma endregion
	
/***************************************************************************************/
/*                                         Tag相关                                      */
/***************************************************************************************/

#pragma region Tag
		
protected:
	/*消息部件数据表*/
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Widget Data")
	TObjectPtr<UDataTable> MessageWidgetDataTable;

	/*委托:消息行*/
	UPROPERTY(BlueprintAssignable, Category="GAS|Messages")
	FOnMessageWidgetRowSignature OnMessageWidgetRowSignature;

	/*通过标签查找数据表行*/
	template<typename T>
	T* GetDataTableRowByTag(UDataTable* DataTable, const FGameplayTag& Tag);

};

template <typename T>
T* UCC_OverlayWidgetController::GetDataTableRowByTag(UDataTable* DataTable, const FGameplayTag& Tag)
{
	return DataTable->FindRow<T>(Tag.GetTagName(), TEXT(""));
}

#pragma endregion

